﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using JM.JCY.BusinessEntity;
using JM.JCY.Proxy;
using NCS.IConnect.ApplicationContexts;
using JM.JCY.Common;
using JM.JCY.Common.Utilities;
using Microsoft.SharePoint;


namespace JM.JCY.SharePointComponent.IncorruptArchives.JianWuDuChaView
{
    public partial class JianWuDuChaViewUserControl : UserControl
    {
        public int _caseId
        {
            set { ViewState["_caseId"] = value; }
            get { return (int)ViewState["_caseId"]; }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                using (IncorruptProxy proxy = new IncorruptProxy())
                {
                    if (Request.QueryString["CaseId"] != null)
                    {
                        _caseId = Int32.Parse(Request.QueryString["CaseId"].ToString());
                    }
                    // load data
                    var loadDT = proxy.GetJianWuDuCha(_caseId, string.Empty, null, null, string.Empty);
                    LoadForEdit(loadDT);
                    LoadForView(loadDT);
                }

            }

            // switch controls
            if (this.hfIsEdit.Value != "1")
                SwitchControls(true, false);
            else
                SwitchControls(false, true);
        }

        private void LoadForView(IncorruptDataSet.T_JianWuDuChaDataTable loadDT)
        {
            var loadRow = loadDT[0];
            this.lblNumber.Text = loadRow.Number;
            this.lblDate.Text = loadRow.Date.ToString(JCYConstant.Date_Format_CN);
            this.lblName.Text = loadRow.Name;
            this.lblDept.Text = loadRow.Dept;
            this.lblDetails.Text = loadRow.Detail;

        }

        private void LoadForEdit(IncorruptDataSet.T_JianWuDuChaDataTable loadDT)
        {
            var loadRow = loadDT[0];
            this.txtNumber.Text = loadRow.Number;
            this.txtName.Text = loadRow.Name;
            this.txtDept.Text = loadRow.Dept;
            this.txtDetails.Text = loadRow.Detail;
            this.hfDate.Value = loadRow.Date.ToString();
        }

        private void SwitchControls(bool isLabelsShow, bool isControlsShow)
        {
            //labels
            this.lblNumber.Visible = isLabelsShow;
            this.lblDate.Visible = isLabelsShow;
            this.lblName.Visible = isLabelsShow;
            this.lblDept.Visible = isLabelsShow;
            this.lblDetails.Visible = isLabelsShow;

            //controls
            this.txtNumber.Visible = isControlsShow;
            this.dtDate.Visible = isControlsShow;
            this.txtName.Visible = isControlsShow;
            this.txtDept.Visible = isControlsShow;
            this.txtDetails.Visible = isControlsShow;
            this.hr4.Visible = isControlsShow;
        }
    }
}
